﻿package mortal.game.view.rebate.data
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;

    public class RebateConfig extends Object
    {
        public var targetArr:Array;
        public var itemObj:Object;
        public var itemShopObj:Object;
        public var dayChargeArr:Array;
        private static var _instance:RebateConfig;

        public function RebateConfig()
        {
            this.targetArr = [];
            this.itemObj = {};
            this.itemShopObj = {};
            this.dayChargeArr = [];
            this.init();
            return;
        }// end function

        private function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_target.json");
            this.writeTTarget(_loc_1);
            var _loc_2:* = ConfigManager.instance.getJSONByFileName("t_recharge_return_config.json");
            this.writeRecharge(_loc_2);
            return;
        }// end function

        private function writeItem() : void
        {
            return;
        }// end function

        private function shopSort(param1:TShopPanicBuyItem, param2:TShopPanicBuyItem) : int
        {
            if (param1.code > param2.code)
            {
                return 1;
            }
            if (param1.code < param2.code)
            {
                return -1;
            }
            if (param1.index > param2.index)
            {
                return 1;
            }
            if (param1.index < param2.index)
            {
                return -1;
            }
            return 0;
        }// end function

        private function writeShop() : void
        {
            return;
        }// end function

        private function writeTTarget(param1:Object) : void
        {
            var _loc_2:* = param1 as Array;
            this.targetArr = _loc_2;
            return;
        }// end function

        public function findByType(param1:int, param2:int) : Object
        {
            var _loc_3:Object = null;
            var _loc_4:int = 0;
            while (_loc_4 < this.targetArr.length)
            {
                
                _loc_3 = this.targetArr[_loc_4];
                if (param1 == _loc_3.type && param2 == _loc_3.targetType && RebateUtil.checkInDate(_loc_3))
                {
                    return _loc_3;
                }
                _loc_4++;
            }
            return null;
        }// end function

        public function findDayRecharge(param1:int, param2:int) : Object
        {
            var _loc_3:Object = null;
            var _loc_4:int = 0;
            while (_loc_4 < this.targetArr.length)
            {
                
                _loc_3 = this.targetArr[_loc_4];
                if (param1 == _loc_3.type && param2 == _loc_3.targetType && _loc_3.refundActiveId && RebateUtil.checkInDate(_loc_3))
                {
                    return _loc_3;
                }
                _loc_4++;
            }
            return _loc_3;
        }// end function

        private function writeRecharge(param1:Object) : void
        {
            var _loc_2:* = param1 as Array;
            this.dayChargeArr = _loc_2;
            return;
        }// end function

        public function findRechargeByGroup(param1:int) : Array
        {
            var _loc_4:Object = null;
            var _loc_2:Array = [];
            var _loc_3:int = 0;
            while (_loc_3 < this.dayChargeArr.length)
            {
                
                _loc_4 = this.dayChargeArr[_loc_3];
                if (param1 == _loc_4.group)
                {
                    _loc_2.push(_loc_4);
                }
                _loc_3++;
            }
            _loc_2.sortOn(["money"], [Array.NUMERIC]);
            return _loc_2;
        }// end function

        public function findRechargeByGroupAndMoney(param1:int, param2:int) : Object
        {
            var _loc_5:Object = null;
            var _loc_3:Array = [];
            var _loc_4:int = 0;
            while (_loc_4 < this.dayChargeArr.length)
            {
                
                _loc_5 = this.dayChargeArr[_loc_4];
                if (param1 == _loc_5.group && param2 == _loc_5.money)
                {
                    return _loc_5;
                }
                _loc_4++;
            }
            return null;
        }// end function

        public static function instance() : RebateConfig
        {
            if (_instance == null)
            {
                _instance = new RebateConfig;
            }
            return _instance;
        }// end function

    }
}
